<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('质检上架单')" />
	<th:block th:include="include :: businessCSS" />
    <style>
        .layui-table-tool{display: none;}
		.tablebody{background-color: #fff;padding: 20px;margin-right: 15px;}
		.tablebody input{display: inline;width: 80%;border: none;}
		.tablebody table{width: 100%;}
		.tablebody th,.tablebody td{border:solid 1px #ddd;padding:10px;font-size:14px;text-align: center;}
		.redcolor{color: red;cursor: pointer;min-width: 40px;}
		.bluecolor{color: rgb(71, 150, 253);cursor: pointer;min-width: 50px;}
    </style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <!-- <th:block th:include="include :: business_btn" /> -->
	        <th:block th:include="include :: business_tpl('top')" />
			
    	</div>
		<div th:if="${enableEdit==1}" style="position: fixed;bottom: 0;width: 100%;background-color: #fff;text-align:center; padding: 15px;">
			<input type="button" style="width: 100px;background: rgb(0, 135, 250);padding: 7px;color: #fff;border: none;border-radius: 10px;cursor: pointe" lay-submit lay-filter="btn-add" id="btn-add" value="保存">
		</div>

    </form>
	<div style="padding: 16px;display: flex;justify-content: space-between;">
		<div  style="font-weight: 700;font-size: 18px;">质检上架单详情</div>
		<div>
			<button class="layui-btn layui-btn-normal dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" onclick="getMore('goodsAllocationPl',null,'货位编号','tcc_goodsallocation')" id="btn-sh">批量修改仓库信息</button>
		</div>
	</div>
	<div class="tablebody">
		<table class="zjtable">
			<thead>
				<tr>
					<th></th><th>子件编码</th><th>子件名称</th><th>FNSKU</th><th>组装数量</th>
					<th>货位编码</th><th>库区</th><th>所在仓库</th><th>上架数量</th><th>操作</th>
				</tr>
			</thead>
		</table>
	</div>
	<div style="width: 100%;height:80px;"></div>
    
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script th:inline="javascript">
	var putawayList=[[${putawayList}]]
	enableEdit =[[${enableEdit}]];

	console.log(putawayList,1)
</script>
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
eachFields();//明细表格中的字段遍历


layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
	 $(document).ready(function(){
		var str=''
		if(putawayList.length>0){
			for(var i=0;i<putawayList.length;i++){
		    	str+='<tbody class="tbody">'
		    	for(var j=0;j<putawayList[i].putawayList.length;j++){
                    if(j==0){
		    			str+=`<tr>
		    		    	<td class="redcolor" rowspan="${putawayList[i].putawayList.length}">+</td>
		    		    	<td class='fsonProductID' rowspan="${putawayList[i].putawayList.length}">${putawayList[i].sonProductID ?putawayList[i].sonProductID :''}</td>
		    		    	<td class='fsonProductName' rowspan="${putawayList[i].putawayList.length}">${putawayList[i].sonProductName ?putawayList[i].sonProductName :''}</td>
		    		    	<td class='ffNSKU' rowspan="${putawayList[i].putawayList.length}">${putawayList[i].fNSKU ?putawayList[i].fNSKU :''}</td>
		    		    	<td class='factualNum' rowspan="${putawayList[i].putawayList.length}">${putawayList[i].actualNum ?putawayList[i].actualNum :''}</td>
		    		    	<td>
		    					<input type="text" name='goodsAllocation' readonly class='goodsAllocation' value='${putawayList[i].putawayList[j].goodsAllocation ?putawayList[i].putawayList[j].goodsAllocation :''}'>
		    					<i class="layui-icon layui-icon-more hlicon" onclick="getMore('goodsAllocation',null,'货位编号','tcc_goodsallocation')"></i>  
		    				</td>
		    		    	<td><input type="text" name='goodsArea' readonly class='goodsArea' value='${putawayList[i].putawayList[j].goodsArea ?putawayList[i].putawayList[j].goodsArea :''}'></td>
		    		    	<td><input type="text" name='warehouseAddress' readonly class='warehouseAddress' value='${putawayList[i].putawayList[j].warehouseAddress ?putawayList[i].putawayList[j].warehouseAddress :''}'></td>
		    		    	<td><input type="number" name='num' class='num' value='${putawayList[i].putawayList[j].num ?putawayList[i].putawayList[j].num :''}'></td>

		    				<input type="hidden" name='guid' class='guid' value='${putawayList[i].putawayList[j].guid}'>
		    				<input type="hidden" name='vHw' class='vHw' value='${putawayList[i].putawayList[j].vHw}'>
		    				<input type="hidden" name='vKq' class='vKq' value='${putawayList[i].putawayList[j].vKq}'>
		    				<input type="hidden" name='gDepot' class='gDepot' value='${putawayList[i].putawayList[j].gDepot}'>
		    				<input type="hidden" name='sonProductID' class='sonProductID' value='${putawayList[i].sonProductID}'>
		    				<input type="hidden" name='sonProductName' class='sonProductName' value='${putawayList[i].sonProductName}'>
		    				<input type="hidden" name='fNSKU' class='fNSKU' value='${putawayList[i].fNSKU}'>
		    				<input type="hidden" name='actualNum' class='actualNum' value='${putawayList[i].actualNum}'>
		    		    	<td style="color:#999;cursor:not-allowed;">删除</td>
		    		    </tr>`
		    		}else{
		    			str+=`<tr>
		    		    	<td>
		    					<input type="text" name='goodsAllocation' readonly class='goodsAllocation' value='${putawayList[i].putawayList[j].goodsAllocation ?putawayList[i].putawayList[j].goodsAllocation :''}'>
		    					<i class="layui-icon layui-icon-more hlicon" onclick="getMore('goodsAllocation',null,'货位编号','tcc_goodsallocation')"></i>  
		    				</td>
		    		    	<td><input type="text" name='goodsArea' readonly class='goodsArea' value='${putawayList[i].putawayList[j].goodsArea ?putawayList[i].putawayList[j].goodsArea :''}'></td>
		    		    	<td><input type="text" name='warehouseAddress' readonly class='warehouseAddress' value='${putawayList[i].putawayList[j].warehouseAddress ?putawayList[i].putawayList[j].warehouseAddress :''}'></td>
		    		    	<td><input type="number" name='num' class='num' value='${putawayList[i].putawayList[j].num ?putawayList[i].putawayList[j].num :''}'></td>
		    				<input type="hidden" name='guid' class='guid' value='${putawayList[i].putawayList[j].guid}'>
		    				<input type="hidden" name='vHw' class='vHw' value='${putawayList[i].putawayList[j].vHw}'>
		    				<input type="hidden" name='vKq' class='vKq' value='${putawayList[i].putawayList[j].vKq}'>
		    				<input type="hidden" name='gDepot' class='gDepot' value='${putawayList[i].putawayList[j].gDepot}'>
		    				<input type="hidden" name='sonProductID' class='sonProductID' value='${putawayList[i].sonProductID}'>
		    				<input type="hidden" name='sonProductName' class='sonProductName' value='${putawayList[i].sonProductName}'>
		    				<input type="hidden" name='fNSKU' class='fNSKU' value='${putawayList[i].fNSKU}'>
		    				<input type="hidden" name='actualNum' class='actualNum' value='${putawayList[i].actualNum}'>
		    		    	<td class="bluecolor">删除</td>
		    		    </tr>`
		    		}
		    	}
		    	str+='</tbody>'
                
		    }
		}else{
			str+=`<tr><td colspan="10">暂无数据</td></tr>`
		}
		
		$('.zjtable').append(str)
	})
	var hlthis=''
	$('body').on('click','.hlicon',function(){
		hlthis=$(this)
	})
	window.getMoreAfter=function(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res){
		if ( fields == 'goodsAllocationPl'){
			$('input[name="goodsAllocation"]').val(res.goodsAllocation);
			$('input[name="goodsArea"]').val(res.goodsArea);
			$('input[name="warehouseAddress"]').val(res.warehouseAddress);
		} else if ( fields == 'goodsAllocation'){
			hlthis.parent().parent().children().children('.goodsAllocation').val(res.goodsAllocation)
			hlthis.parent().parent().children().children('.goodsArea').val(res.goodsArea)
			hlthis.parent().parent().children().children('.warehouseAddress').val(res.warehouseAddress)
		}

	}
// 添加行
	$('body').on('click','.redcolor',function(){
		var str=`<tr>
					<td>
						<input type="text" name='goodsAllocation' readonly class='goodsAllocation' value=''>
						<i class="layui-icon layui-icon-more hlicon" onclick="getMore('goodsAllocation',null,'货位编号','tcc_goodsallocation')"></i>  
					</td>
					<td><input type="text" name='goodsArea' readonly class='goodsArea' value=''></td>
					<td><input type="text" name='warehouseAddress' readonly class='warehouseAddress' value=''></td>
					<td><input type="number" name='num' class='num' value=''></td>
					<input type="hidden" name='guid' class='guid' value=''}'>
					<input type="hidden" name='sonProductID' class='sonProductID' value='${$(this).nextAll(".fsonProductID").text()}'>
					<input type="hidden" name='vHw' class='vHw' value='${$(this).nextAll(".vHw").val()}'>
					<input type="hidden" name='vKq' class='vKq' value='${$(this).nextAll(".vKq").val()}'>
					<input type="hidden" name='gDepot' class='gDepot' value='${$(this).nextAll(".gDepot").val()}'>
					<input type="hidden" name='sonProductName' class='sonProductName' value='${$(this).nextAll(".fsonProductName").text()}'>
					<input type="hidden" name='fNSKU' class='fNSKU' value='${$(this).nextAll(".ffNSKU").text()}'>
					<input type="hidden" name='actualNum' class='actualNum' value='${$(this).nextAll(".factualNum").text()}'>
					<td class="bluecolor">删除</td>
				</tr>`
		$(this).attr('rowspan',+$(this).attr('rowspan')+1)
		$(this).nextAll("td").each(function(i){
			if($(this).attr('rowspan')){
				$(this).attr('rowspan',+$(this).attr('rowspan')+1)
			}
		})
		
		$(this).parent().parent().append(str)
	})
	
	// 删除行
	$('body').on('click','.bluecolor',function(){
		$(this).parent().remove();
	})
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/storage/putaway/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		initTable();//初始化表格
	});

	toolbarEvent();//通用表格头部工具栏事件监听
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染
	moneyCalculation();//表格编辑——资金计算
    form.on('submit(btn-add)', function(data){
		var daraArr=[]
		var isxd=true
        $('.tbody').each(function (i,s) {
            var a=''
            var addnum=0
            $(this).children('tr').each(function (v) {
                if(v==0) a=+$(this).children('.factualNum').text()
                addnum=addnum+(+$(this).children().children('.num').val())
            })
            if(a!=addnum)isxd=false

        })
        if(!isxd)return layer.msg('上架数量不符')
		var isjx=true
		$('.tbody tr').each(function (i) {
			let obj={}
			obj.guid=$(this).children('.guid').val()
			obj.sonProductID=$(this).children('.sonProductID').val()
			obj.vHw=$(this).children('.vHw').val()
			obj.vKq=$(this).children('.vKq').val()
			obj.gDepot=$(this).children('.gDepot').val()
			obj.sonProductName=$(this).children('.sonProductName').val()
			obj.fNSKU=$(this).children('.fNSKU').val()
			obj.actualNum=$(this).children('.actualNum').val()

			obj.goodsAllocation=$(this).children().children('.goodsAllocation').val()
			obj.goodsArea=$(this).children().children('.goodsArea').val()
			obj.warehouseAddress=$(this).children().children('.warehouseAddress').val()
			obj.num=$(this).children().children('.num').val()
			if(!obj.goodsAllocation || !obj.num)isjx=false
			daraArr.push(obj)
		})
		if(!isjx)return layer.msg('请填写货位编码和上架数量')
        $.operate.post("/storage/putaway/editpost",{'infoMap':JSON.stringify(data.field),nid:$('#nid').val(),infoItems:JSON.stringify(daraArr)},function(res){
            layer.msg(res.msg)
            if(res.code==0){
                setTimeout(function(){
                    window.location.reload();
                }, 1000);
            }
        	
        })

    })
})
</script>
</body>
</html>